package cn.yh.springbootjwt.controller.base;



import cn.yh.springbootjwt.common.AjaxResult;
import cn.yh.springbootjwt.common.TableDataInfo;

import java.lang.reflect.Field;

public class BaseController {
    protected TableDataInfo dataInfo(Object rows, Long total){
    TableDataInfo dataInfo = new TableDataInfo();
        dataInfo.setCode(200);
        dataInfo.setMsg("操作成功");
        dataInfo.setRows(rows);
        dataInfo.setTotal(total);
        return dataInfo;
    }

    public static AjaxResult toAjax(int row){
        return row > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    public static boolean checkAllFieldsNotNull(Object obj) {
        try {
            for (Field field : obj.getClass().getDeclaredFields()) {
                field.setAccessible(true);
                Object value = field.get(obj);
                if (value == null || (value instanceof String && ((String) value).trim().isEmpty())) {
                    return false;
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
